function register() {
	location.replace("html/register.html")
};
// 账号登录
function loginByAccount() {
	$.ajax({
		url : "/user/loginByAccount",
		type : "post",
		data : {
			account : $("#account").val(),
			pwd : $("#pwd2").val(),
			loginImgCode : $("#loginCode2").val()
		},
		success : function(data) {
			if (data.result.indexOf("成功") != -1) { // 用户名登录判断登录的是否是管理员，如果是管理员，跳转至管理员后台
				if (data.role == "admin") {
					location.href = "index_admin.jsp";
				} else if (data.role == "student") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/studentCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				} else if (data.role == "coach") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/coachCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				} else if (data.role == "gym") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/gymCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				}
			} else {
				alert(data.result);
			}
		}
	});
}
// 手机登录
function loginByPhone() {
	$.ajax({
		url : "/user/loginByPhone",
		type : "post",
		data : {
			uphone : $("#account1").val(),
			pwd : $("#pwd1").val(),
			loginImgCode : $("#loginCode1").val()
		},
		success : function(data) {
			if (data.result.indexOf("成功") != -1) {
				if (data.role == "student") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/studentCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				} else if (data.role == "coach") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/coachCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				} else if (data.role == "gym") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/gymCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				}
			} else {
				alert(data.result);
				window.location.reload();
			}
		}
	});
}
// 邮箱登录
function loginByMail() {
	$.ajax({
		url : "/user/loginByMail",
		type : "post",
		data : {
			umail : $("#mail").val(),
			pwd : $("#pwd3").val(),
			loginImgCode : $("#loginCode3").val()
		},
		success : function(data) {
			if (data.result.indexOf("成功") != -1) {
				if (data.role == "student") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/studentCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				} else if (data.role == "coach") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/coachCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				} else if (data.role == "gym") {
					if (data.Mes1 == "noAdd") {
						alert("登陆成功！请完善您的基本信息！");
						location.href = "html/gymCompile.html";
					} else {
						if (data.Mes2 == "noLock") {
							location.href = "home.jsp";
						} else {
							showAlert(data.Mes2);
						}
					}
				}
			} else {
				alert(data.result);
				window.location.reload();
			}
		}
	});
}

//弹出封禁信息提示框
function showAlert(cpReason){
	var changeMes="";
	 changeMes+='<div class="container">'
		 +'<div class="boxOuter">您的账户涉及违反规则限制登录，如需恢复账户请提交申诉！</div>'
		 +'<div class="boxOuter"><div class="boxInner">账户封禁原因：</div><div class="boxInner">'+cpReason+'</div></div>'
		 +'<div class="boxOuter" style="margin-top:20px">'
		 +'<input type="button" class="profile-card__button button--blue js-message-btn" style="width: 100px;min-height:40px;height:40px;font-size:15px;line-height:15px;" onclick="toComplain()" value="前往申诉"/>'
		 +'<input type="button" class="profile-card__button button--orange" style="width: 100px;min-height:40px;height:40px;font-size:15px;line-height:15px;" onclick="method.msg_close()" value="取消"/>'
		 +'</div>';
    var obj={
        type:"showSweetAlert",
        title:"账户违规通知",
        content:changeMes,
        area:["600px","200px"]
    };
    method.msg_layer(obj);
}

function toComplain(){
	location.replace("Complain.jsp");
}

function findPwd(){
	location.href="http://localhost:8080/jsp/findPwd.jsp";
}
